package com.woniu.order.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ConfigurationProperties(prefix = "alipay.config")
@Configuration
@Data
public class AlipayConfiguration {
    private String serverUrl;
    private String appid;
    private String privateKey;
    private String alipayPublicKey;
    @Bean
    public AlipayClient config() throws Exception {
//        System.out.println(appid);
//        System.out.println("===================appid==================");
//        AlipayConfig alipayConfig = new AlipayConfig();
//        //设置网关地址
//        alipayConfig.setServerUrl(serverUrl);
//        //设置应用ID
//        alipayConfig.setAppId(appid);
//        //设置应用私钥
//        alipayConfig.setPrivateKey(privateKey);
//        //设置支付宝公钥
//        alipayConfig.setAlipayPublicKey(alipayPublicKey);
//        //设置请求格式固定值json
//        alipayConfig.setFormat("JSON");
//        //设置字符集
//        alipayConfig.setCharset("UTF-8");
//        //设置签名类型
//        alipayConfig.setSignType("RSA2");
//        //实例化客户端
//        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
//        return alipayClient;

        //<-- 请填写您的应用私钥，例如：MIIEvQIBADANB ... ... -->
        String privateKey  = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCmRAbq3rKQvo2rUwTNp1ye65ZViSjnVJLCdb9u1GcsCnGelmprj1u8jys8eeIeQmtC6RSiKNogtltKHqpmcdDqZeyZlmMlEmJE/3CqVk7A44zNLpVXweFb4RAa0P5GDiWeUrWg3St7Q0rQeuaR8FVD9MaOSGkmOyqLjvOPjTFWXqop7vXGpwkevA5I4C5HZIrok/tViO5XAdAALTX8udAZA0cDoOT+Fa8SeUktHX7dcQrwmoDNMM77sTZqu7Byh7zRXI+LUWBNhnLti2Z4rNTD8+vYYK36/1fcT8/+TWPqlXtWv2N/kwxf3ObqMZwLwD69ezXhleZGPWdiUUg90opnAgMBAAECggEAO4r1JzulmyyCs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GIG2XA58L5sBr1ZFAF8W44/SP7N0QMTOpKToajA97mtY/GUJZR0lS27mOsOB47VfuwL0wrUo9QDixbaiBQtdalqeNTDMBcsQOfiR2wobaN6d4ythNL7NOWyoZJbY";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
//        <-- 请填写您的AppId，例如：2019091767145019 -->
        alipayConfig.setAppId("9021000135689676");
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        alipayConfig.setFormat("json");
//        <-- 请填写您的应用公钥证书文件路径，例如：/foo/appCertPublicKey_2019051064521003.crt -->
        alipayConfig.setAppCertPath("C:/Users/liuz5/Downloads/appPublicCert.crt");
//        <-- 请填写您的支付宝公钥证书文件路径，例如：/foo/alipayCertPublicKey_RSA2.crt -->
        alipayConfig.setAlipayPublicCertPath("C:/Users/liuz5/Downloads/alipayPublicCert.crt");
//        <-- 请填写您的支付宝根证书文件路径，例如：/foo/alipayRootCert.crt -->
        alipayConfig.setRootCertPath("C:/Users/liuz5/Downloads/alipayRootCert.crt");
        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
        return alipayClient;
    }
}
